import { FlowModel } from '../models/flow';
import { NotFound } from 'lin-mizar/lin';

class Flow {
  static async addFlow (cf) {
    const af = await FlowModel.create({
      index: cf.get('body.index'),
      type: cf.get('body.type'),
      art_id: cf.get('body.art_id'),
      status: cf.get('body.status')
    });
    return af;
  }
  static async getFlowList () {
    const flowList = await FlowModel.findAll({
      order: ['index'] // 依据index字段进行排序
    });
    return flowList;
  }
  static async editFlow (id, index, type, art_id, status) {
    const flow = await FlowModel.findByPk(id);
    if (!flow) {
      throw new NotFound();
    }
    const upf = await flow.update({ index, type, art_id, status });
    return upf;
  }
  static async deleteFlow (id) {
    const flow = await FlowModel.findByPk(id);
    if (!flow) {
      throw new NotFound();
    }
    await flow.destroy();
  }
}
export { Flow as FlowDao };
